<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="1000"  destroy-on-close @closed="$emit('closed')" align-center>
        <el-button type="primary" @click="print">打印</el-button>
        <el-main class="printMain" ref="printMain">
            <div style="margin-bottom: 30px">
                <div class="title">{{summary_time}}(威大)</div>
            </div>
            <table border style="border-collapse: collapse; width: 100%;">
                <tbody style="height: 32px;line-height: 32px;">
                    <tr>
                        <td class="table_border">配货情况</td>
                        <td class="table_border">已配货单数:</td>
                        <td class="table_border">{{detail.distribution?.allocated_orders || 0}}单</td>
                        <td class="table_border">未配货单数:</td>
                        <td class="table_border">{{detail.distribution?.unallocated_orders || 0}}单</td>
                    </tr>
                    <tr>
                        <td class="table_border" rowspan="2">销售情况</td>
                        <td class="table_border">销售单数:</td>
                        <td class="table_border">{{detail.sales?.sale_count || 0}}单</td>
                        <td class="table_border">退货匹数:</td>
                        <td class="table_border">{{detail.sales?.return_count || 0}}匹</td>
                    </tr>
                    <tr>
                        <td class="table_border">销售总额(含运费):</td>
                        <td class="table_border">{{detail.sales?.total_sales_amount || 0}}</td>
                        <td class="table_border">退货总额:</td>
                        <td class="table_border">{{detail.sales?.return_total_amount || 0}}</td>
                    </tr>
                    <tr>
                        <td class="table_border" rowspan="3">财务情况</td>
                        <td class="table_border">前一日汇款收入:</td>
                        <td class="table_border">{{detail.finance?.previous_day_bank_income || 0}}</td>
                        <td class="table_border">前一日汇款开支:</td>
                        <td class="table_border">{{detail.finance?.previous_day_bank_expense || 0}}</td>
                    </tr>
                    <tr>
                        <td class="table_border">前一日现金收入:</td>
                        <td class="table_border">{{detail.finance?.previous_day_cash_income || 0}}</td>
                        <td class="table_border">前一日现金开支:</td>
                        <td class="table_border">{{detail.finance?.previous_day_cash_expense || 0}}</td>
                    </tr>
                    <tr>
                        <td class="table_border">当前汇款结余:</td>
                        <td class="table_border">{{detail.finance?.current_bank_balance || 0}}</td>
                        <td class="table_border">当前现金结余:</td>
                        <td class="table_border">{{detail.finance?.current_cash_balance || 0}}</td>
                    </tr>
                    <tr>
                        <td class="table_border" colspan="5">
                            当前总结余: {{detail.summary?.total_summary || 0}}
                        </td>
                    </tr>
                </tbody>
            </table>
        </el-main>
	</el-dialog>
</template>

<script>
import print from '@/utils/print'
export default {
	emits: ['success', 'closed'],
	data() {
			return {
				dialog: {
					client: false
				},
				mode: "add",
				titleMap: {
					print: '打印',
				},
				visible: false,
                detail: {},
                summary_time: "",
			}
		},
	mounted() {
	},
	methods: {
        print(){
            print(this.$refs.printMain)
            setTimeout(()=>{
                this.visible = false
            },500)
        },
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        async setData(time) {
            this.summary_time = time
            var res = await this.$API.business.sale.daySummary.post({date: time});
            this.detail = res.data;
        },
	}
}
</script>

<style lang="scss" scoped>
.title {
    font-size: 22px;
    text-align: center;
    font-weight: bold;
    margin-bottom: 10px;
}
td{
    text-align: center;
}
.table_border{
    width: 80px;
    height: 32px;
    border: 1px solid #000;
}
table{
    tbody{
        font-size: 13px;
        tr {
            page-break-inside: avoid;
            -webkit-region-break-inside: avoid; 
        }
        tr:last-child{
            page-break-after: avoid;
            
        }
    }
} 
</style>
